#include <stdio.h>
#include <stdlib.h>
#include "Stack.h"



int ReallocArray(Stack *array)
{
    ElementType *temp = array->s;
    array->size = array->size * 2;
    array->s = (ElementType *)malloc(sizeof(ElementType) * array->size);
    if(array->s== NULL)
    {
        printf("ReallocArray error!\n");
        array->s = temp;
        array->size = array->size / 2;
        return false;
    }

    for(int i = 0; i < array->len; i++)
    {
        array->s[i] = temp[i];
    }

    free(temp);
    temp=NULL;
    return true;

}
int InitStack(Stack *array)
{
    array->s = (ElementType *)malloc(sizeof(ElementType) * array->size);
    if(array->s == NULL)
    {
        printf("malloc error!\n");
        return false;
    }
    return true;
}
void FreeStack(Stack *array)
{
    if(array->s != NULL)
    {
        free(array->s);
        array->s = NULL;
        array->len = 0;
    }
}
void push(Stack* s,ElementType element)
{
    if(s->len>=s->size)
    {
        printf("error\n");
        return;
    }
    s->s[s->len++]=element;
}

ElementType pop(Stack *s)
{
    if(s->len==0)
    {
        printf("empty stack\n");
    }
    return s->s[--s->len];
}



void main()
{
    Stack s0;
    s0.len=0;
    // for(int i=0;i<5;i++)
    // {
    //     push(&s0,i+1);
    // }
    // while(s0.len!=0)
    // {
    //     printf("%d ",pop(&s0));
    // }
    // printf("\n");

    int num;
    printf("please intput a number:");
    scanf("%d",&num);
    int n=0;
    printf("please intput a system number:");
    scanf("%d",&n);
    while(num)
    {
        push(&s0,num%n);
        num=num/n;
    }
    while(s0.len!=0)
    {
        printf("%d",pop(&s0));
    }
    printf("\n");
}